import {defineStore} from "pinia";
import { useCartStore } from "./cartStore.ts";
import * as UserApi from '../apis/user.ts'
export const useUserStore = defineStore('user', {
    state: () => {
        return {
            id: '',
            username: '',
            avatar: '',
            token: '',
            isLogin: false,
            modalVisible: false,
        }
    },

    actions: {
        getInfo() {
            UserApi.getInfo()
                .then((res) => {
                    if (res.code === 200) {
                        const cartStore = useCartStore()
                        cartStore.getCartList(res.data.id)
                        this.id = res.data.id;
                        this.username = res.data.username
                        this.isLogin = true
                        this.modalVisible= false
                    }
                })
                .catch((res) => {
                    console.log('error', res)
                })
        }
    },
    persist:true
})


